// pages/download-file/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading:true,
    category: '',
    expriments:[
      // {name:'移位寄存器及其应用', imageUrl: 'https://7465-test-0gnibtq0d1e1243a-1304764432.tcb.qcloud.la/%E5%AE%9E%E9%AA%8Cicon.png?sign=650bdd86a6437a28620c66269af318c7&t=1620786889', category: '数字电路实验室', exIndex: 1},
      // {name:'同步计数器及其应用', imageUrl: 'https://7465-test-0gnibtq0d1e1243a-1304764432.tcb.qcloud.la/%E5%AE%9E%E9%AA%8Cicon.png?sign=650bdd86a6437a28620c66269af318c7&t=1620786889', category: '数字电路实验室', exIndex: 2},
      // {name:'基本RS和D触发器的应用', imageUrl: 'https://7465-test-0gnibtq0d1e1243a-1304764432.tcb.qcloud.la/%E5%AE%9E%E9%AA%8Cicon.png?sign=650bdd86a6437a28620c66269af318c7&t=1620786889', category: '数字电路实验室', exIndex: 3},
      // {name:'编码器与显示译码器的应用', imageUrl: 'https://7465-test-0gnibtq0d1e1243a-1304764432.tcb.qcloud.la/%E5%AE%9E%E9%AA%8Cicon.png?sign=650bdd86a6437a28620c66269af318c7&t=1620786889', category: '数字电路实验室', exIndex: 4},
      // {name:'数据选择器及二进制译码器的应用', imageUrl: 'https://7465-test-0gnibtq0d1e1243a-1304764432.tcb.qcloud.la/%E5%AE%9E%E9%AA%8Cicon.png?sign=650bdd86a6437a28620c66269af318c7&t=1620786889', category: '数字电路实验室', exIndex: 5},
      // {name:'基本RS和D触发器的应用', imageUrl: 'https://7465-test-0gnibtq0d1e1243a-1304764432.tcb.qcloud.la/%E5%AE%9E%E9%AA%8Cicon.png?sign=650bdd86a6437a28620c66269af318c7&t=1620786889', category: '数字电路实验室', exIndex: 6}
    ]
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      category: options.category
    })
    this.getExprimentsList()
    var timeout = setTimeout(()=>{
      this.setData({
        loading: false
      })
    })
  },

  // 获取实验列表
  getExprimentsList(){
    wx.cloud.callFunction({
      name: 'getExprimentsList',
      data:{
        category: this.data.category
      }
    }).then(res=>{
      // console.log(res)
      this.setData({
        expriments: res.result.data
      })
    })
  },

  // 跳转到更多页面
  seeDetail(e){
    wx.navigateTo({
      url: "/pages/experiment/details?exprimentName=" + e.currentTarget.dataset.target,
    })
  },

  // 按名称搜索
  searchbyname(e){
    // console.log(e.detail)
    wx.cloud.callFunction({
      name: 'getExpByName',
      data:{
        name: e.detail
      }
    }).then(res=>{
      console.log(res)
      this.setData({
        expriments: res.result.data
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    clearTimeout(timeout)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})